<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>闭包练习</title>
</head>
<body>
    <script>
        //9.
        var x = 100;
        var y = 200;
        function funcA( x ){
            var y = 201;
            function funcB(){
                console.log(x);//101
                console.log(y);//201
            }
            return funcB;
        }

        var f = funcA(101);
        f();

        // 10. 
        // function Foo(){
        //     var i = 0;
        //     return function(){
        //         console.log(i++);
        //     }
        // }
        // var f1 = Foo();
        // var f2 = Foo();
        // f1();
        // f2();
        // f2();

        //11. 
        function f1(){
            var n = 999;
            nAdd = function(){n+=1};
            function f2(){
                console.log(n)
            };
            return f2;
        }
        var result = f1();
        result();
        nAdd();
        result();
    </script>
</body>
</html>